package org.papillion39.sechelper.data.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Jonathan Paz <jonathan.paz@ottr.com>
 */
@Entity
@Table(name = "membership_record")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MembershipRecord.findAll", query = "SELECT m FROM MembershipRecord m"),
    @NamedQuery(name = "MembershipRecord.findById", query = "SELECT m FROM MembershipRecord m WHERE m.id = :id")})
public class MembershipRecord implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(nullable = false)
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 2147483647)
    @Column(name = "record_type", nullable = false, length = 2147483647)
    private String recordType;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_effective", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateEffective;
    @Temporal(TemporalType.DATE)
    private Date expires;
    @JoinColumn(name = "membership_id", referencedColumnName = "id", nullable = false)
    @ManyToOne(optional = false)
    private Membership membershipId;

    public MembershipRecord() {
    }

    public MembershipRecord(Integer id) {
        this.id = id;
    }

    public MembershipRecord(Integer id, String recordType, Date dateEffective) {
        this.id = id;
        this.recordType = recordType;
        this.dateEffective = dateEffective;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getRecordType() {
        return recordType;
    }

    public void setRecordType(String recordType) {
        this.recordType = recordType;
    }

    public Date getDateEffective() {
        return dateEffective;
    }

    public void setDateEffective(Date dateEffective) {
        this.dateEffective = dateEffective;
    }

    public Date getExpires() {
        return expires;
    }

    public void setExpires(Date expires) {
        this.expires = expires;
    }

    public Membership getMembershipId() {
        return membershipId;
    }

    public void setMembershipId(Membership membershipId) {
        this.membershipId = membershipId;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 19 * hash + Objects.hashCode(this.id);
        hash = 19 * hash + Objects.hashCode(this.recordType);
        hash = 19 * hash + Objects.hashCode(this.membershipId);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final MembershipRecord other = (MembershipRecord) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.recordType, other.recordType)) {
            return false;
        }
        if (!Objects.equals(this.membershipId, other.membershipId)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "MembershipRecord{" + "id=" + id + ", recordType=" + recordType + ", dateEffective=" + dateEffective + ", expires=" + expires + ", membershipId=" + membershipId + '}';
    }

}
